<template>
  <div>
    <el-table
      v-loading="$store.getters.loading"
      :data="$store.getters.postlist"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="设备编号" align="center" prop="deviceName" />
      <el-table-column label="设备id" align="center" prop="id" />
      <el-table-column label="设备名称" align="center" prop="deviceId" />
      <el-table-column
        label="设备状态"
        align="center"
        prop="state"
      
      ><template slot-scope="scope">{{ scope.row.state | sta }}</template>
      </el-table-column>
      <el-table-column
        label="创建时间"
        align="center"
        prop="createDate"
        width="180"
      >
        <!-- <template slot-scope="scope">
          <span>{{ scope.row.createDate }}</span>
        </template> -->
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:post:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:post:remove']"
            >删除</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:post:remove']"
            >激活</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="设备名称" prop="postName">
          <el-input v-model="form.deviceName" placeholder="请输入设备名称" />
        </el-form-item>
        <el-form-item label="设备编码" prop="postCode">
          <el-input v-model="form.deviceId" placeholder="请输入设备编码" />
        </el-form-item>
        <el-form-item label="设备id" prop="id">
         <el-input v-model="form.id" placeholder="请输入设备id" />
        </el-form-item>
        <el-form-item label="设备状态" prop="status">
          <el-input v-model="form.state" placeholder="请输入设备状态" />
        </el-form-item>
        
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <pagination
      v-show="$store.getters.total > 0"
      :total="$store.getters.total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import {update,deldev,querydev} from '@/api/zhu/index.js'

export default {
  name: "Devall",
   created() {
    //  console.log(this.postList);
    this.getList();
    
  },
  filters:{
      sta(tt){
          return tt==2?'未激活':'已激活';
      }
  },
  data() {
    return {
      // 遮罩层
      
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      
      // 岗位表格数据
      
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 状态数据字典
      statusOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        postCode: undefined,
        postName: undefined,
        status: undefined,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        // postName: [
        //   { required: true, message: "名称不能为空", trigger: "blur" },
        // ],
        // postCode: [
        //   { required: true, message: "编码不能为空", trigger: "blur" },
        // ],
        // postSort: [
        //   { required: true, message: "id不能为空", trigger: "blur" },
        // ],
      },
    };
  },
  methods: {
    statusFormat(){

    },
    submitForm(){
      update({id:this.form.id},this.form).then((res)=>{
       this.open=false
      })

    },
    cancel(){
console.log('quxiao');
this.open=false
    },
    getList() {
      this.loading = true;

      this.$store.dispatch('zhu/toglist',this.queryParams)
     
       
      // getdev(this.queryParams).then((response) => {
      //   // console.log(777777777777);
      //   // console.log(response);
       
      // });
    },
    handleSelectionChange(e) {
    this.ids=e.map(item=>{
      return item.id
    })
    this.$store.commit('zhu/hhh',this.ids);
      console.log(this.ids);
    },
    handleUpdate(e) {
      this.open = true;
      querydev({id:e.id}).then(res=>{
       this.form= res.element;
       
      });

      
    },
    handleDelete(e) {
      console.log(e);
      this.$confirm('是否确认删除设备id为"'+ e.id + '"的数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(function() {
        console.log(e.id);
          return deldev({id:e.id});
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        });
    },
  },
};
</script>

<style rel="stylesheet/scss" lang="scss">
ul {
  padding: 0;
  margin: 0;
  list-style: none;
}
</style>